import axios from 'axios'
import { Message } from 'element-ui'

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  withCredentials: false,
  timeout: 5000
})

service.interceptors.response.use(
  response => {
    const { data } = response
    return data
  },
  error => {
    const { data } = error.response
    if (process.env.NODE_ENV === 'development') {
      console.log(data)
    }
    Message({
      message: data.message,
      type: 'warning',
      duration: 3 * 1000
    })
    return Promise.reject(data)
  }
)

export default service
